home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / c / run.c < prev    next >
C/C++ Source or Header  |  1996-09-13  |  2KB  |  113 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: run.c,v 1.4 1996/09/13 17:52:11 digulla Exp $
  4.     $Log: run.c,v $
  5.     Revision 1.4  1996/09/13 17:52:11  digulla
  6.     Use IPTR
  7.  
  8.     Revision 1.3  1996/08/01 17:40:45  digulla
  9.     Added standard header for all files
  10.  
  11.     Desc:
  12.     Lang:
  13. */
  14. #include <exec/memory.h>
  15. #include <clib/exec_protos.h>
  16. #include <dos/dosextens.h>
  17. #include <dos/dostags.h>
  18. #include <clib/dos_protos.h>
  19. #include <utility/tagitem.h>
  20.  
  21. CALLENTRY /* Before the first symbol */
  22.  
  23. struct ExecBase *SysBase;
  24. struct DosLibrary *DOSBase;
  25.  
  26. static LONG tinymain(void);
  27.  
  28. LONG entry(struct ExecBase *sysbase)
  29. {
  30.     LONG error=RETURN_FAIL;
  31.     SysBase=sysbase;
  32.     DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",39);
  33.     if(DOSBase!=NULL)
  34.     {
  35.     error=tinymain();
  36.     CloseLibrary((struct Library *)DOSBase);
  37.     }
  38.     return error;
  39. }
  40.  
  41. static LONG tinymain(void)
  42. {
  43.     STRPTR args[1]={ 0 };
  44.     struct RDArgs *rda;
  45.     BPTR in, out, shell;
  46.     STRPTR s1, s2, buf;
  47.     struct Process *process;
  48.     ULONG num;
  49.     LONG error=0;
  50.  
  51.     rda=ReadArgs("COMMAND/A/F",(IPTR *)args,NULL);
  52.     if(rda!=NULL)
  53.     {
  54.     error=RETURN_ERROR;
  55.     s1=s2=(STRPTR)args[0];
  56.     while(*s2++)
  57.         ;
  58.     buf=(STRPTR)AllocVec(8+s2-s1,MEMF_ANY);
  59.     if(buf!=NULL)
  60.     {
  61.         CopyMem("COMMAND ",buf,8);
  62.         CopyMem(s1,buf+8,s2-s1);
  63.         shell=LoadSeg("c:shell");
  64.         if(shell)
  65.         {
  66.         in=Open("CONSOLE:",MODE_OLDFILE);
  67.         if(in)
  68.         {
  69.             out=Open("CONSOLE:",MODE_NEWFILE);
  70.             if(out)
  71.             {
  72.             struct TagItem tags[]=
  73.             {
  74.                 { NP_Name, (IPTR)"Background task" },
  75.                 { NP_Arguments, 0 },
  76.                 { NP_Input, 0 },
  77.                 { NP_Output, 0 },
  78.                 { NP_Error, 0 },
  79.                 { NP_Seglist, 0 },
  80.                 { NP_Cli, 1 },
  81.                 { TAG_END, 0 }
  82.             };
  83.             tags[1].ti_Data=(IPTR)buf;
  84.             tags[2].ti_Data=in;
  85.             tags[3].ti_Data=out;
  86.             tags[5].ti_Data=shell;
  87.             Forbid();
  88.             process=CreateNewProc(tags);
  89.             if(process!=NULL)
  90.             {
  91.                 num=process->pr_TaskNum;
  92.                 out=in=shell=0;
  93.                 error=0;
  94.             }
  95.             Permit();
  96.             Close(out);
  97.             if(process&&VPrintf("[CLI %ld]\n",&num)<0)
  98.                error=RETURN_ERROR;
  99.             }
  100.             Close(in);
  101.         }
  102.         UnLoadSeg(shell);
  103.         }
  104.         FreeVec(buf);
  105.     }
  106.     FreeArgs(rda);
  107.     }else
  108.     error=RETURN_FAIL;
  109.     if(error)
  110.     PrintFault(IoErr(),"Run");
  111.     return error;
  112. }
  113.